package com.pass.two;

import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;

/**
 * Pass Two collects all the output files of Pass One Reducer, does union find
 * on all the edges that involve intersection edges, outputs the union find
 * result <-1, edge edge edge...> to file.
 * 
 * @author bh349
 */
public class PassTwo extends Configured implements Tool {

	public int run(String[] args) throws Exception {
		Job job = new Job(getConf(), "pass 2");
		job.setJarByClass(PassTwo.class);
		job.setMapperClass(PassTwoMapper.class);
		job.setReducerClass(PassTwoReducer.class);
		job.setOutputKeyClass(IntWritable.class);
		job.setOutputValueClass(Text.class);
		FileInputFormat.addInputPaths(job, "pass1out");
		FileOutputFormat.setOutputPath(job, new Path("pass2out"));
		return job.waitForCompletion(true) ? 0 : 1;
	}
}
